//
//  WYRTwoViewController.m
//  10-21-快速搭建框架
//
//  Created by lkx0 on 16/10/21.
//  Copyright © 2016年 lkx0. All rights reserved.
//

#import "WYRTwoViewController.h"
#import "WYRNavigationController.h"
#import "WYRChatViewController.h"
#import "WYROneViewController.h"


@interface WYRTwoViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(strong, nonatomic) UITableView * tbView;
@property(strong, nonatomic) NSMutableArray * friendsArr;

//用一个数组保存plilst文件中的所有好友
@property(strong, nonatomic) NSArray * plistArr;
@end

@implementation WYRTwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //将plist文件中的数组转成plistArr
     //1.获取plist文件
 //   NSString * path=[[NSBundle mainBundle]pathForResource:@"friends" ofType:@"plist"];
    NSString * path =[[NSBundle mainBundle]pathForResource:@"friends.plist" ofType:nil];
    //2.通过路径取数据
    self.plistArr =[NSArray arrayWithContentsOfFile:path];
    NSLog(@"数据：%@",self.plistArr);
    
    self.view.backgroundColor=[UIColor greenColor];
    self.tabBarController.tabBar.hidden= NO;
    self.navigationItem.title=@"动态";
    
    //导航栏的item
   // UIBarButtonItem * barItem=[[UIBarButtonItem alloc]initWithTitle:@"用户" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    
    //添加一个tableView
    self.tbView=[[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    [self.view addSubview:self.tbView];
    
   //设置代理
    _tbView.dataSource=self;
    _tbView.delegate=self;
    
//    //设置数据
//    self.friendsArr=[NSMutableArray array];
//    for(int i=1;i<=9;i++){
//        NSArray * arr=@[[NSString stringWithFormat:@"小明%d号",i],[NSString stringWithFormat:@"%d",i]];
//        [_friendsArr addObject:arr];
//    }
//    // Do any additional setup after loading the view.
}

//-(void)back{
//    WYROneViewController * one=[[WYROneViewController alloc]init];
//    [self.navigationController pushViewController:one animated:YES];
//}
#pragma mark -数据源方法
//返回多少行（没有分组，普通样式）
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  //  return _friendsArr.count;
    return _plistArr.count;
}

//2.返回每一行的cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell * cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    
  //  cell.textLabel.text=[_friendsArr[indexPath.row] objectAtIndex:0];
    
    cell.textLabel.text=[_plistArr [indexPath.row] objectForKey:@"name"];
    
 //   NSString * imgName=[_friendsArr[indexPath.row] objectAtIndex:1];
    
    NSString * imgName=[_plistArr[indexPath.row] objectForKey:@"icon"];
    cell.imageView.image=[UIImage imageNamed:imgName];
    
    return cell;
}


//-(void)viewWillAppear:(BOOL)animated{
//    self.hidesBottomBarWhenPushed = NO;
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


// cell的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //创建要显示的聊天界面视图控制器
    WYRChatViewController * chat=[[WYRChatViewController alloc]init];
    //创建一个属于chat的导航栏
       WYRNavigationController * nav=[[WYRNavigationController alloc]initWithRootViewController:chat];
    //设置导航栏的标题
    chat.title=[_plistArr[indexPath.row] objectForKey:@"name"];

    //跳转到这个导航栏
   [self presentViewController:nav animated:YES completion:nil];
   }






/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
